package aiku.numericalcontroloa.Service.unitMeasure;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Mapper.unitMeasure.unitMeasureMapper;
import aiku.numericalcontroloa.Model.Entity.unitMeasure.unitMeasure;

@Service
public class unitMeasureServiceImp implements unitMeasureService {

    @Autowired
    private unitMeasureMapper unitMeasureMapper;

    @Override
    public Result getUnitMeasure() {
        List<unitMeasure> unitMeasureList = unitMeasureMapper.selectList(null);
        return Result.success("查询完成",unitMeasureList);
    }

    @Override
    public Result addUnitMeasure(unitMeasure data) {
        if (data == null && data.getUnitMeasure() == null) {
            return Result.error("参数为空");
        }
        data.setDeleted(0);
        data.setId(null);
        if (unitMeasureMapper.insert(data) == 1) {
            return Result.success("添加成功");
        }else{
            return Result.error("添加失败");
        }
    }

    @Override
    public Result setUnitMeasure(unitMeasure data) {
        if (data == null && data.getUnitMeasure() == null) {
            return Result.error("参数为空");
        }
        if (unitMeasureMapper.updateById(data) == 1) {
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }

    @Override
    public Result deleteUnitMeasure(unitMeasure data) {
        if (data == null) {
            return Result.error("参数为空");
        }
        data.setDeleted(1);
        if (unitMeasureMapper.deleteById(data) == 1) {
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }
}
